import { createRouter, createWebHashHistory } from 'vue-router'

import Layout from '@/views/Layout'
import Home from '../views/Home'
import Login from '../views/Login'
import Category from '@/views/Category/index.vue'
// 二级类目组件
import SubCategory from '@/views/Category/Sub/index.vue'
// 导入详情页
import Goods from '@/views/Goods/index.vue'

const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      {
        path: '/',
        component: Home
      },
      // 一级类目
      {
        path: '/Category/:id',
        component: Category
      },
      // 二级类目
      {
        path: '/category/sub/:id',
        component: SubCategory
      },
      // 详情页
      {
        path: '/Goods/:id',
        component: Goods
      }
    ]
  },

  {
    path: '/login',
    name: 'Login',
    component: Login
  }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

// 创建路由实例
const router = createRouter({
  // 使用hash方式实现路由
  history: createWebHashHistory(),
  // 配置路由规则 , 写法和vue2.0一样
  routes
})

export default router
